package com.example.springblog.model;

import com.example.springblog.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T> {
    //业务码： 枚举类型，SUCCESS成功，FAIL失败，……（在另一个包下的类中）
    private ResultStatus code;
    //错误信息
    private String errMsg;
    //接口响应的数据《/*待解惑。待完善。*/》
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }
    public static <T> Result<T> fail(String errMsg , T data) {
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
